import 'abort_event.dart';
import 'accept_event.dart';
import 'deliver_event.dart';
import 'refuse_event.dart';
import 'task_expecta.dart';
import 'package:word_game/engine/core.dart';
import 'taskable_npc.dart';

class Task extends Sightable {
  /// 任务所属者
  TaskableNPC owner;
  /// 领取任务者
  Hero receiver;
  String desc = '';
  /// 初始化物品代码
  String initThingCode= '';
  String require = '';
  String thingCode = '';
  TaskExpecta expecta;
  /// 奖励事物代码
  String rewardThingCode = '';

  Task(String name) : super(name) {
    
  }

  @override
  void copyData(dynamic obj) {
    this.owner = obj.owner;
    this.receiver = obj.receiver;
    this.desc = obj.desc;
    this.require = obj.require;
    this.thingCode = obj.thingCode;
    this.expecta = obj.expecta;
    this.rewardThingCode = this.rewardThingCode;
    super.copyData(obj);
  }

  void accepted(){

  }

  @override
  String optionCommandsDesc() {
    String result = desc;
    if (expecta.expecta(World.instance.hero, this)) {
      result += '[任务已完成]';
    } else {
      result += '[任务未完成]';
    }
    var hero = World.instance.hero;
    var hasAccept = 
    owner.taskStates['${this.code}_${hero.name}'] == 'accept';
    if (hasAccept) {
      removeByName(AcceptEvent());
      removeByName(RefuseEvent());
      keepOne(DeliverEvent());
      keepOne(AbortEvent());
    } else {
      removeByName(DeliverEvent());
      removeByName(AbortEvent());
      keepOne(AcceptEvent());
      keepOne(RefuseEvent());
    }
    result += '\n' + super.optionCommandsDesc();
    return result;
  }
}